package com.carl.zlds.controller.web;

import com.carl.zlds.annotation.Login;
import com.carl.zlds.controller.BaseController;
import com.carl.zlds.pojo.dto.AccountSearchDTO;
import com.carl.zlds.pojo.vo.GameAccountVO;
import com.carl.zlds.service.IGameAccountService;
import com.carl.zlds.tool.common.PageBO;
import com.carl.zlds.tool.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

/**
 * @author carl
 */
@Slf4j
@RestController(value = "web.gameAccountController")
@RequestMapping("/web/game-account")
@Api(tags = {"客户端 - 游戏账号管理"})
public class GameAccountController extends BaseController {

    private final IGameAccountService gameAccountService;

    @Autowired
    public GameAccountController(IGameAccountService gameAccountService) {
        this.gameAccountService = gameAccountService;
    }

    @ApiOperation("顶级账号列表")
    @GetMapping(value = "/top-level-list")
    @Login(needToken = false)
    public Result<Map<String, Object>> topLevelList(@RequestParam(value = "gameId", defaultValue = "0") Long gameId,
                                                    @RequestParam(value = "limit", defaultValue = "10") Integer limit) {
        Map<String, Object> map = gameAccountService.getTopLevelList(gameId, limit);
        return Result.success(map);
    }

    @ApiOperation("账号列表")
    @GetMapping(value = "/home-list")
    @Login(needToken = false)
    public Result<Map<String, Object>> homeList(@RequestParam(value = "gameId", defaultValue = "0") Long gameId,
                                                @RequestParam(value = "top_level", defaultValue = "0") Integer topLevel,
                                                @RequestParam(value = "up", defaultValue = "0") Integer up,
                                                @RequestParam(value = "limit", defaultValue = "10") Integer limit) {
        Map<String, Object> map = gameAccountService.getHomeList(gameId, topLevel, up, limit);
        return Result.success(map);
    }

    @ApiOperation("最新账号")
    @GetMapping(value = "/home-latest-list")
    @Login(needToken = false)
    public Result<Map<String, Object>> homeLatestList(@RequestParam(value = "gameId", defaultValue = "0") Long gameId,
                                                      @RequestParam(value = "yesterday", defaultValue = "0") Integer yesterday,
                                                      @RequestParam(value = "limit", defaultValue = "10") Integer limit) {
        Map<String, Object> map = gameAccountService.getHomeLatestList(gameId, yesterday, limit);
        return Result.success(map);
    }

    @ApiOperation("顶级账号成交")
    @GetMapping(value = "/top-level-deal")
    @Login(needToken = false)
    public Result<Map<String, Object>> topLevelDeal(@RequestParam(value = "gameId", defaultValue = "0") Long gameId) {
        Map<String, Object> map = gameAccountService.getTopLevelDeal(gameId);
        return Result.success(map);
    }

    @ApiOperation("成交统计")
    @GetMapping(value = "/stat-deal")
    @Login(needToken = false)
    public Result<Map<String, Object>> statDeal(@RequestParam(value = "gameId", defaultValue = "0") Long gameId) {
        Map<String, Object> map = gameAccountService.statDeal(gameId);
        return Result.success(map);
    }

    @ApiOperation("账号详情")
    @GetMapping(value = "/info")
    @Login(needToken = false)
    public Result<GameAccountVO> info(@RequestParam("gameId") Long gameId,
                                      @RequestParam(value = "id") Long id) {
        GameAccountVO vo = gameAccountService.getInfo(gameId, id);
        return Result.success(vo);
    }

    @ApiOperation("筛选搜索")
    @GetMapping(value = "/search")
    @Login(needToken = false)
    public Result<Map<String, Object>> search(@Valid AccountSearchDTO accountSearchDTO,
                                              PageBO pageBO) {
        Map<String, Object> map = gameAccountService.accountSearch(accountSearchDTO, pageBO);
        return Result.success(map);
    }
}
